<?php defined('SYSPATH') or die('No direct script access.');
 
class myfile 
{
    public static function move($original, $destination)
    {
    	if(!is_file($original)) return FALSE;
		
		if(self::_create_folder(dirname($destination)))
		{
			if(file_exists($destination)) unlink($destination);
			copy($original, $destination);
			unlink($original);
		}
			
		return $destination;
    }
	
	protected function _create_folder($folder)
	{
    	$folder = explode( "/" , $folder);
		$mkfolder = '';
		
		for(  $i=0 ; isset( $folder[$i] ) ; $i++ )
		{
			$mkfolder .= $folder[$i];
			
			if( $mkfolder != '' and ! is_dir( $mkfolder ) )
				mkdir( $mkfolder ,  0777);
				
			$mkfolder .= '/';
		}
		
		return TRUE;
	}
}